/*
 * (c) 2007, Delsi Interactive
 * User: Usuario Deltatek
 * Date: 16/04/2007
 * Time: 09:44 p.m.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace CSE
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
	    /*
	     * Variables
	     */
	    public static MainForm self = null;
	    public static TreeNode libClipsRoot = null;
	    public static TreeNode libBitmap = null;
	    
		[STAThread]
		public static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new MainForm());
		}
		
		public MainForm()
		{
			InitializeComponent();
			self = this;
			this.DoubleBuffered = true;
		}
		
		/*
		 * MainFormLoad
		 */
		void MainFormLoad(object sender, EventArgs e)
		{
			this.spriteToolStripMenuItem.Visible = false;
		}
		
		/*
		 * MainFormResize
		 */
		void MainFormResize(object sender, EventArgs e)
		{
			this.picStage.Invalidate();
		}
		
		/*
		 * MainFormSetDefaults
		 */
		public void MainFormSetDefaults ()
		{
			if (Workspace.type == Workspace.TYPE_SPRITE)
			{
				this.spriteToolStripMenuItem.Visible = true;
				
				CreateSpriteLibrary();
			}
			else
			{
			}
		}
		
		/*
		 * CreateSpriteLibrary
		 */
		private void CreateSpriteLibrary ()
		{
			ImageList myImageList = new ImageList();
			myImageList.Images.Add(Utils.LoadBitmapResource("clip.Bitmap"));
		    myImageList.Images.Add(Utils.LoadBitmapResource("bitmap.Bitmap"));
		    
		    this.treeLibrary.ImageList = myImageList;
		    this.treeLibrary.ImageIndex = 0;
		    
		    libClipsRoot = this.treeLibrary.Nodes.Add("_root", "_root", 0, 0);
		    libBitmap = this.treeLibrary.Nodes.Add("_bitmap", "_bitmap", 1, 1);
		    
		    libBitmap.Nodes.Add("_bitmap_source", "(null)", 1, 1);
		}
		
		/*
		 * File/New
		 */
		void NewToolStripMenuItemClick(object sender, EventArgs e)
		{
		    Workspace.Shutdown();
		    Workspace.Init();
		    
		    this.picStage.Invalidate();
		}
		
		/*
		 * File/Preferences
		 */
		void PreferencesToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}

		/*
		 * Sprite/Get clips
		 */
		void GetClipsToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}

		/*
		 * Sprite/Set source image
		 */
		void SetSourceImageToolStripMenuItemClick(object sender, EventArgs e)
		{
			OpenFileDialog ofdSprite = new OpenFileDialog();
            ofdSprite.Filter = "PNG Image Files |*.png";
            ofdSprite.Multiselect = false;
            
            if (ofdSprite.ShowDialog() == DialogResult.OK)
            {
            	Workspace.SetSourceBitmap(ofdSprite.FileName);
            	libBitmap.Nodes.Clear();
            	libBitmap.Nodes.Add("_bitmap_source", ofdSprite.FileName, 1, 1);
            }
		}
		
		/*
		 * PicStagePaint
		 */
		void PicStagePaint(object snder, PaintEventArgs e)
		{
		    Stage.Draw(e.Graphics, this.picStage.Width, this.picStage.Height);
		}		
	}
}
